package org.kl.bpm.utils;

import java.util.HashMap;
import java.util.Map;

import org.kl.bpm.rule.AssigneeRule;
import org.kl.bpm.rule.PositionAssigneeRule;
import org.kl.bpm.rule.RuleMatcher;
import org.kl.bpm.rule.SuperiorAssigneeRule;
import org.kl.bpm.rule.UserAssigneeRule;

/**
 * @Author hqm
 * @CreateTime 2014年8月28日 上午11:18:59
 */
public class AssigneeRuleUtils {
	private static Map<RuleMatcher, AssigneeRule> assigneeRuleMap = new HashMap<RuleMatcher, AssigneeRule>();
	static {
		SuperiorAssigneeRule superiorAssigneeRule = new SuperiorAssigneeRule();
		PositionAssigneeRule positionAssigneeRule = new PositionAssigneeRule();
		UserAssigneeRule userAssigneeRule = new UserAssigneeRule();
		assigneeRuleMap.put(new RuleMatcher("常用语"), superiorAssigneeRule);
		assigneeRuleMap.put(new RuleMatcher("岗位"), positionAssigneeRule);
		assigneeRuleMap.put(new RuleMatcher("人员"), userAssigneeRule);
	}

	public static String getAssignee(String origin) {
		for (Map.Entry<RuleMatcher, AssigneeRule> entry : assigneeRuleMap.entrySet()) {
			RuleMatcher ruleMatcher = entry.getKey();
			if (!ruleMatcher.matches(origin)) {
				continue;
			}
			return ruleMatcher.getValue(origin);
		}
		return null;
	}
}
